﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Configuration;
using System.Web;
using System.IO;

namespace Core.DS
{
    public static partial class CourseDesign
    {
        public static dynamic showCDStatistics(int cid)
        {
            var sql = new Sql.SqlDataContext();
            var result = from s in sql.DSClassStudent
                         where s.cid == cid
                         orderby s.id
                         join u in sql.User
                         on s.sid equals u.sid
                         into uo
                         let ui = uo.FirstOrDefault()
                         join cd in sql.CourseDesign
                         on ui.username equals cd.username
                         into cdo
                         let cdi = cdo.FirstOrDefault()
                         select new
                         {
                             id = s.id,
                             name = s.name,
                             sid = s.sid,
                             hasUpload = cdi == null ? 0 : 1,
                             point = cdi.point
                         };
            return new
            {
                success = true,
                result,
                count = result.Count()
            };
        }
    }
}
